package com.ce.utils;

import java.io.File;

import android.util.Log;

public class FileUtils {

	private final static String TAG = "FileUtils";

	public synchronized  static boolean isFileExists(String fileName) {
		if (fileName == null || "".equals(fileName.trim())) {
			Log.d(DishDefine.TAG, "the 'fileName' is empty");
			return false;
		}
		File file = new File(DishDefine.PARENT_PATH + "/" + fileName);
		return isFileExists(file);
	}

	public synchronized static boolean isFileExists(File file) {
		if (file == null) {
			Log.d(DishDefine.TAG, "the 'fileName' is empty");
			return false;
		}
		return file.exists();
	}

	public static boolean createMkdirs(String mkdir) {
		String mkDirStr = null;
		Log.d(TAG, DishDefine.PARENT_PATH);
		if (mkdir == null || "".equals(mkdir.trim())) {
			mkDirStr = DishDefine.PARENT_PATH;
			Log.d(DishDefine.TAG, "the 'mkdir' is empty");
		} else {
			mkDirStr = DishDefine.PARENT_PATH + "/" + mkdir;
		}
		File file = new File(mkDirStr);
		return createMkdirs(file);
	}

	public  static boolean createMkdirs(File file) {
		if (file == null) {
			Log.d(DishDefine.TAG, "the paramer 'file' is null .");
			return false;
		}

		if (isFileExists(file)) {
			Log.d(DishDefine.TAG, "the " + file.getName() + " exists .");
			return true;
		}
		boolean res = false;
		try {
			res = file.mkdirs();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}
}
